package com.woniu.mall.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.mall.VO.HotProductVO;
import com.woniu.mall.VO.ProductDetailVO;
import com.woniu.mall.VO.ProductListVO;
import com.woniu.mall.pojo.MallProduct;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 坤
 * @since 2023-05-22
 */
public interface MallProductMapper extends BaseMapper<MallProduct> {

    List<ProductListVO> listSearch(String title);

    ProductDetailVO showDetail(Integer pid);

    @Select("select store_id from t_mall_product where product_id = #{pid}")
    Integer getStoreId(Integer pid);

    List<HotProductVO> hotProduct(Integer num);

    List<ProductListVO> listByCategory(String category);

    String getCategoryIcon(String category);

    @Update("update from t_mall_product set stock = stock + 1 where product_id = #{pid}")
    Integer addStock(Integer pid);

    @Update("update from t_mall_product set stock = stock - 1 where product_id = #{pid}")
    Integer reduceStock(Integer pid);

    @Select("select store_id, stock from t_mall_product where product_id = #{productId}")
    MallProduct getProduct(Integer productId);
    @Select("select product_id, store_id, stock from t_mall_product")
    @ResultType(MallProduct.class)
    List<MallProduct> getAllProduct();

    @Update("update t_mall_product set stock = stock - #{itemQuantity} where product_id = #{productId}")
    void updateStock(@Param("productId") Integer productId, @Param("itemQuantity") Integer itemQuantity);
}
